package com.example.p2p;

import java.io.IOException;
import java.net.*;
import java.nio.charset.StandardCharsets;

public class Send {

    public static void main(String[] args) throws IOException {
        String msg = "您好";
        byte[] data = msg.getBytes(StandardCharsets.UTF_8);
        InetAddress group = InetAddress.getByName("228.5.6.7");
        MulticastSocket s = new MulticastSocket(6789);
        //加入多播组
        s.joinGroup(group);
        //创建一个数据包封装多播信息
        DatagramPacket hi = new DatagramPacket(data,data.length,group,6789);
        //发送
        s.send(hi);
    }
}
